package com.example.yichuangyun.utils.treelist;

import com.example.yichuangyun.R;

import java.util.ArrayList;
import java.util.List;

public class Node {

    /**
     * 设置开启 关闭的图片
     */
    private int iconExpand = R.mipmap.icon_up, iconNoExpand = R.mipmap.icon_down;

    private String id;
    /**
     * 根节点pId为0
     */
    private String pId;

    private String parentId;

    private int isDept;
    private int isLeave;

    private int isDepart;

    private String name;

    private String fullId;

    private String jobNumber;
    private String orgId;

    /**
     * 是否展开
     */
    private boolean isExpand = false;

    private int icon = -1;

    /**
     * 下一级的子Node
     */
    private List<Node> children = new ArrayList<>();
    private List<Node> userList = new ArrayList<>();

    /**
     * 父Node
     */
    private Node parent;
    /**
     * 是否被checked选中
     */
    private boolean isChecked;
    /**
     * 是否为新添加的
     */
    public boolean isNewAdd = true;

    public boolean isChecked() {
        return isChecked;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public int getIsDept() {
        return isDept;
    }

    public void setIsDept(int isDept) {
        this.isDept = isDept;
    }

    public void setChecked(boolean isChecked) {
        this.isChecked = isChecked;
    }

    public Node(String name, String id, String pId, Integer isDept, String fullId, String jobNumber, String orgId) {
        super();
        this.id = id;
        this.pId = pId;
        this.name = name;
        this.isDept = isDept;
        this.fullId = fullId;
        this.jobNumber = jobNumber;
        this.orgId = orgId;
    }

    public Node(String name, String id, String pId, Integer isDept, String fullId, String jobNumber, String orgId, int isLeave) {
        super();
        this.id = id;
        this.pId = pId;
        this.name = name;
        this.isDept = isDept;
        this.fullId = fullId;
        this.jobNumber = jobNumber;
        this.orgId = orgId;
        this.isLeave = isLeave;
    }

    public int getIsDepart() {
        return isDepart;
    }

    public void setIsDepart(int isDepart) {
        this.isDepart = isDepart;
    }

    public int getIsLeave() {
        return isLeave;
    }

    public void setIsLeave(int isLeave) {
        this.isLeave = isLeave;
    }

    public String getFullId() {
        return fullId;
    }

    public void setFullId(String fullId) {
        this.fullId = fullId;
    }

    public String getJobNumber() {
        return jobNumber;
    }

    public void setJobNumber(String jobNumber) {
        this.jobNumber = jobNumber;
    }

    public String getOrgId() {
        return orgId;
    }

    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }

    public int getIcon() {
        return icon;
    }

    public void setIcon(int icon) {
        this.icon = icon;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getpId() {
        return pId;
    }

    public void setpId(String pId) {
        this.pId = pId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isExpand() {
        return isExpand;
    }

    public List<Node> getChildren() {
        return children;
    }

    public void setChildren(List<Node> children) {
        this.children = children;
    }

    public List<Node> getUserList() {
        return userList;
    }

    public void setUserList(List<Node> userList) {
        this.userList = userList;
    }

    public Node getParent() {
        return parent;
    }

    public void setParent(Node parent) {
        this.parent = parent;
    }

    public int getIconExpand() {
        return iconExpand;
    }

    public void setIconExpand(int iconExpand) {
        this.iconExpand = iconExpand;
    }

    public int getIconNoExpand() {
        return iconNoExpand;
    }

    public void setIconNoExpand(int iconNoExpand) {
        this.iconNoExpand = iconNoExpand;
    }

    /**
     * 是否为跟节点
     */
    public boolean isRoot() {
        return parent == null;
    }

    /**
     * 判断父节点是否展开
     */
    public boolean isParentExpand() {
        if (parent == null)
            return false;
        return parent.isExpand();
    }

    /**
     * 是否是叶子界点
     */
    public boolean isLeaf() {
        return children.size() == 0;
    }

    /**
     * 获取level
     */
    public int getLevel() {
        return parent == null ? 0 : parent.getLevel() + 1;
    }

    /**
     * 设置展开
     */
    public void setExpand(boolean isExpand) {
        this.isExpand = isExpand;
        if (!isExpand) {
            for (Node node : children) {
                node.setExpand(false);
            }
        }
    }
}
